<template>
  <el-menu
    class="el-menu-vertical-demo"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="skyblue"
    :default-active="$route.path"
    router
    unique-opened
    :collapse="isCollapse"
  >
    <h4 v-show="!isCollapse">小滴后台管理系统</h4>
    <h4 v-show="isCollapse">小滴</h4>
    <el-menu-item
      :index="item.path"
      v-for="item in noChildMenu"
      :key="item.id"
      @click="menuClick(item)"
    >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>

    <el-submenu :index="item.label" v-for="item in hasChildMenu" :key="item.id">
      <template slot="title">
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group v-for="child in item.children" :key="child.id">
        <el-menu-item :index="child.path" @click="menuClick(child)">
          <i :class="'el-icon-' + child.icon"></i>
          {{ child.label }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>
import { mapState } from "vuex"
export default {
  name: "",
  data () {
    return {
    }
  },
  computed: {
    noChildMenu () {
      return this.asideMenu.filter((item) => !item.children)
    },

    hasChildMenu () {
      return this.asideMenu.filter((item) => item.children)
    },

    ...mapState({
      isCollapse: (state) => state.tabs.isCollapse,
      asideMenu: state => state.tabs.menu
    }),
  },
  methods: {
    menuClick (item) {
      this.$store.commit("selectMenu", item)
    },
  },
}
</script>
<style lang="less" scoped>
.el-menu {
  height: 100%;
  border: none;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

h4 {
  color: #fff;
  text-align: center;
  line-height: 40px;
}
</style>
